package com.youyi.yyfilepickerlibrary.core;

import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.support.v4.app.Fragment;
import com.youyi.yyfilepickerlibrary.core.activity.SelectFileByBrowserActivity;
import com.youyi.yyfilepickerlibrary.core.activity.SelectFileByScanActivity;
import com.youyi.yyfilepickerlibrary.core.activity.SelectPictureActivity;

public final class SelectCreator {
    private String chooseType;
    public final FilePicker filePicker;
    private final SelectOptions selectOptions = SelectOptions.getCleanInstance();

    public SelectCreator(FilePicker filePicker2, String str) {
        this.chooseType = str;
        this.filePicker = filePicker2;
    }

    public SelectCreator setMaxCount(int i) {
        this.selectOptions.maxCount = i;
        if (i <= 1) {
            this.selectOptions.maxCount = 1;
            this.selectOptions.isSingle = true;
        } else {
            this.selectOptions.isSingle = false;
        }
        return this;
    }

    public SelectCreator setCompressImage(boolean z) {
        this.selectOptions.compressImage = z;
        return this;
    }

    public SelectCreator setTargetPath(String str) {
        this.selectOptions.targetPath = str;
        return this;
    }

    public SelectCreator setTheme(int i) {
        this.selectOptions.themeId = i;
        return this;
    }

    public SelectCreator setFileTypes(String... strArr) {
        this.selectOptions.mFileTypes = strArr;
        return this;
    }

    public SelectCreator setSortType(String str) {
        this.selectOptions.mSortType = str;
        return this;
    }

    public SelectCreator isSingle() {
        this.selectOptions.isSingle = true;
        this.selectOptions.maxCount = 1;
        return this;
    }

    public SelectCreator isFolder(boolean z) {
        this.selectOptions.isFolder = z;
        return this;
    }

    public SelectCreator onlyShowImages() {
        this.selectOptions.onlyShowImages = true;
        return this;
    }

    public SelectCreator onlyShowVideos() {
        this.selectOptions.onlyShowVideos = true;
        return this;
    }

    public SelectCreator placeHolder(Drawable drawable) {
        this.selectOptions.placeHolder = drawable;
        return this;
    }

    public SelectCreator enabledCapture(boolean z) {
        this.selectOptions.enabledCapture = z;
        return this;
    }

    public SelectCreator requestCode(int i) {
        this.selectOptions.request_code = i;
        return this;
    }

    public void start() {
        Activity activity = this.filePicker.getActivity();
        if (activity != null) {
            Intent intent = new Intent();
            if (this.chooseType.equals(SelectOptions.CHOOSE_TYPE_BROWSER)) {
                intent.setClass(activity, SelectFileByBrowserActivity.class);
            } else if (this.chooseType.equals(SelectOptions.CHOOSE_TYPE_SCAN)) {
                intent.setClass(activity, SelectFileByScanActivity.class);
            } else if (this.chooseType.equals(SelectOptions.CHOOSE_TYPE_MEDIA)) {
                intent.setClass(activity, SelectPictureActivity.class);
            } else {
                return;
            }
            Fragment fragment = this.filePicker.getFragment();
            if (fragment != null) {
                fragment.startActivityForResult(intent, this.selectOptions.request_code);
            } else {
                activity.startActivityForResult(intent, this.selectOptions.request_code);
            }
        }
    }
}
